package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName IndexFrontController
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/6/23
 * @Version 1.0
 */
@RestController
@RequestMapping("/eduservice/index")
//@CrossOrigin
public class IndexFrontController {
    @Autowired
    EduCourseService eduCourseService;
    @Autowired
    EduTeacherService eduTeacherService;

    /**
     * 1、根据id降序查询出热门课程和名师
     * 2、也可以根据课程浏览数降序查询热门课程
     * @return
     */
    @GetMapping("/indexlimit")
    public R indexlimit(){
        //查询热门课程
        QueryWrapper<EduCourse> courseQueryWrapper=new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id").last("limit 8");
        List<EduCourse> eduCourseList = eduCourseService.list(courseQueryWrapper);
        //查询名师
        QueryWrapper<EduTeacher> teacherQueryWrapper=new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id").last("limit 4");
        List<EduTeacher> eduTeacherList = eduTeacherService.list(teacherQueryWrapper);
        return R.ok().data("courseList",eduCourseList).data("teacherList",eduTeacherList);
    }
}
